package com.yanqu.road.server.cmd.union.cross.honors;

import com.yanqu.road.entity.union.honors.UnionHonorsPointData;
import com.yanqu.road.pb.union.cross.CrossUnionHonorsProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionReqContext;
import com.yanqu.road.server.manager.union.honors.CrossUnionHonorsMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_UNION_GET_UNION_HONORS_POINT, desc = "获取商会荣誉点")
public class CrossGetUnionHonorsPointCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossUnionReqContext context = CrossUnionReqContext.initContext(serverId, packet.getPlayerId()).loadUnionMember().loadUnionInfo();

        if(context.getRet() != 0){
            return;
        }

        CrossUnionHonorsProto.GetUnionHonorsPointRespMsg.Builder respMsg = CrossUnionHonorsProto.GetUnionHonorsPointRespMsg.newBuilder();
        respMsg.setRet(0);
        List<UnionHonorsPointData> list = CrossUnionHonorsMgr.getHonorsPointList(context.getUnionInfo().getUnionUid());
        if(list != null){
            for (UnionHonorsPointData data : list) {
                CrossUnionHonorsProto.UnionHonorsPointTemp.Builder builder = CrossUnionHonorsProto.UnionHonorsPointTemp.newBuilder();
                builder.setActivityChildType(data.getActivityChildType());
                builder.setActivityType(data.getActivityType());
                builder.setHonors(data.getHonors());
                builder.setLastUpdateTime(data.getLastUpdateTime());
                respMsg.addPoint(builder);
            }
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_UNION_GET_UNION_HONORS_POINT, respMsg));
    }

    @Override
    public void sendData() {

    }
}
